package redis

import (
	"fmt"
	"github.com/go-redis/redis/v7"
	"user-membership/rpc/appconfig"
)

var (
	RedisClient *redis.Client
	err         error
)

func InitRedis() {
	add := appconfig.AppConf.RedisConfig
	addr := fmt.Sprintf("%s", add.Host)
	RedisClient = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	_, err = RedisClient.Ping().Result()
	if err != nil {
		fmt.Println("redis 连接失败", err)
		return
	}
	fmt.Println("redis 连接成功")
}
